package com.jbob.collection;

/**
 * Classe de collection de terme
 * @author lucas.bouabdelli jean-baptiste.guy
 */
public class Terme
{
	private String nom;
	private String positions;
	private double poids;
	private int nbOccurences;
	
	public Terme() 
	{
		nbOccurences = 0;
	}
	
	public String getNom() 
	{
		return nom;
	}
	
	public void setNom(String nom) 
	{
		this.nom = nom;
	}

	public double getPoids() {
		return poids;
	}

	public void setPoids(double poids) {
		this.poids = poids;
	}
	public String getPositions() 
	{
		return positions;
	}
	
	public void setPositions(String positions) 
	{
		this.positions = positions;
	}
	
	public int getNbOccurences() 
	{
		return nbOccurences;
	}
	
	public void setNbOccurences(int nbOccurences) 
	{
		this.nbOccurences = nbOccurences;
	}
	
	public void addOccurenceAt(int position)
	{
		nbOccurences++;
		if(positions == null || positions.isEmpty())
		{
			positions = String.valueOf(position);
		}
		else
		{
			positions = positions + "," +  String.valueOf(position);
		}
	}
	
	public void addOccurencesAt(String positions)
	{
		nbOccurences = positions.split(",").length;
		this.positions = positions;
	}
	
	@Override
	public boolean equals(Object obj) 
	{
		if(obj instanceof Terme)
		{
			if(((Terme)obj).getNom().equals(this.nom))
			{
				return true;
			}
		}
		return false;
	}
	
	@Override
	public String toString() 
	{
		return nom + " : " + positions + " : " + nbOccurences;
	}
}
